import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_demo/common_widget/listVIew/list_view.dart';
import 'package:flutter_demo/common_widget/provider_widget/src/provider_1.dart';

import 'future_builder_stream/futureBuildStream.dart';
import 'my_text_field/my_self_field.dart';

// import 'my_text_field/my_self_field.dart';

class IndexPageDemo extends StatefulWidget {
  IndexPageDemo({Key key}) : super(key: key);

  @override
  _IndexPageDemoState createState() => _IndexPageDemoState();
}

class _IndexPageDemoState extends State<IndexPageDemo> {
  @override
  Widget build(BuildContext context) {
    final navList = [
      {'title': '自定义键盘', 'widget': MySelfField()},
      {'title': 'provider', 'widget': ProviderExample1()},
      {'title': 'listView Demo', 'widget': ListVIewDemo()},
      {'title': 'FutureBuilderStream', 'widget': FutureBuilderStream()},
    ];
    return Scaffold(
        appBar: AppBar(
          title: Text('公共组件'),
        ),
        body: GridView.builder(
            itemCount: navList.length,
            //SliverGridDelegateWithFixedCrossAxisCount 构建一个横轴固定数量Widget
            gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
              //横轴元素个数
              crossAxisCount: 2,
              //纵轴间距
              mainAxisSpacing: 20.0,
              //横轴间距
              crossAxisSpacing: 10.0,
              childAspectRatio: 8 / 2,
            ),
            itemBuilder: (BuildContext context, int index) {
              //Widget Function(BuildContext context, int index)
              return getItemContainer(navList[index]);
            }));
  }

  Widget getItemContainer(data) {
    return ElevatedButton(
        style: ButtonStyle(
          textStyle: MaterialStatePropertyAll(TextStyle(color: Colors.white)),
          backgroundColor: MaterialStatePropertyAll(Colors.blue),
        ),
        child: Text(data['title']),
        onPressed: () {
          Navigator.push(
            context,
            CupertinoPageRoute(
              builder: (BuildContext context) => data['widget'],
            ),
          );
        });
  }
}
